﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
//
using System.Web.Caching;
using System.Data;
using System.Data.SqlClient;
using OsPortal;
/// <summary>
/// Summary description for clsChuDeTinTuc
/// </summary>
public class clsChuDeTinTuc
{
    static string strClassName = "clsChuDeTinTuc";

	public clsChuDeTinTuc()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    /// <summary>
    /// Author: NguyenTV
    /// Create Date: 21/10/2013
    /// </summary>
    /// <param name="strCD_ID"></param>
    /// <param name="strCD_NAME_EN"></param>
    /// <param name="strPrentID"></param>
    /// <param name="iTrangThai"></param>
    /// <returns></returns>
    public static DataTable fncChuDeTinTuc_FND(string strCD_ID, string strCD_NAME_EN, string strPrentID, int iTrangThai)
    {
        // Lấy tham chiếu đến đối tượng Cache.
        Cache _cache = HttpContext.Current.Cache;
        string strCacheCDTenKhongDau = "ChuDeTenKhongDau";
        DataTable dtData = null;
        try
        {
            if (_cache[strCacheCDTenKhongDau] == null)
            {
                dtData = oSqlDataHelper.sExecuteDataTable("CHUDETINTUC_FND", new SqlParameter[]{
                new SqlParameter("@P_CD_ID",strCD_ID)
                ,new SqlParameter("@P_CD_TENKHONGDAU",strCD_NAME_EN)
                ,new SqlParameter("@P_CD_PARENTID",strPrentID)
                ,new SqlParameter("@P_CD_TRANGTHAI",iTrangThai)
                });

                // Lưu giữ item trong cache
                // cùng với sliding expiration là 60 giây.
                HttpContext.Current.Cache.Insert(strCacheCDTenKhongDau, dtData, null, DateTime.MaxValue, TimeSpan.FromSeconds(60));
            }
            else
            {
                dtData = (DataTable)_cache[strCacheCDTenKhongDau];
            }
            return dtData;
        }
        catch (Exception ex)
        {
            OsPortal.oFileHelper.WriteLogErr(strClassName, "fncChuDeTinTuc_FND", ex.ToString());
            return null;
        }
        finally
        {
            //dtData.Dispose();
        }
    }

    /// <summary>
    /// Lấy chi tiết chuyên mục tin tức tên không dấu.
    /// Author: NguyenTV
    /// Create: 04/09/2013
    /// </summary>
    /// <param name="strCMtenkhongdau"></param>
    /// <returns></returns>
    public static DataTable fncGetCM_BY_nameEN(string strCMtenkhongdau)
    {
        DataTable dtChuyenMuc = null;
        try
        {
            dtChuyenMuc = OsPortal.oSqlDataHelper.sExecuteDataTable("select cd_ten from chudetintuc where cd_tenkhongdau='" + strCMtenkhongdau + "'");
        }
        catch (Exception ex)
        {
            OsPortal.oFileHelper.WriteLogErr(strClassName, "fncGetCM_BY_nameEN", ex.ToString());
        }
        return dtChuyenMuc;
    }


}